﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BawangMemo.BackendModels
{
    /// <summary>
    /// Word card that contains detail information about the word to show at the view.
    /// In order to reduce memory use, the singleton pattern is applied to this class,
    /// i.e. only one instance exists at runtime.
    /// </summary>
    public class WordCard
    {
        private static WordCard instance;

        public static WordCard GetInstance()
        {
            return instance;
        }

        public static void SetInstance(string spell, string meaning, string synonym, string antonym, string remember,
            string leifan, string derivation, string place, string webster)
        {
            instance = new WordCard(spell, meaning, synonym, antonym, remember, leifan, derivation, place, webster);
        }

        public string Spell { get; set; }
        public string Meaning { get; set; }
        public string Synonym { get; set; }
        public string Antonym { get; set; }
        public string Remember { get; set; }
        public string Leifan { get; set; }
        public string Derivation { get; set; }
        public string Place { get; set; }
        public string Webster { get; set; }

        private WordCard(string spell, string meaning, string synonym, string antonym, string remember,
            string leifan, string derivation, string place, string webster)
        {
            Spell = Helper.replaceSpecialChars(spell.ToLower());
            Meaning = Helper.replaceSpecialChars(meaning);
            Synonym = Helper.replaceSpecialChars(synonym);
            Antonym = Helper.replaceSpecialChars(antonym);
            Remember = Helper.replaceSpecialChars(remember);
            Leifan = Helper.replaceSpecialChars(leifan);
            Derivation = Helper.replaceSpecialChars(derivation);
            Place = Helper.replaceSpecialChars(place);
            Webster = Helper.replaceSpecialChars(webster);
        }

        public static WordCard CreateInstance(string spell, string meaning, string synonym, string antonym, string remember,
            string leifan, string derivation, string place, string webster)
        {
            SetInstance(spell, meaning, synonym, antonym, remember, leifan, derivation, place, webster);
            return instance;
        }
    }
}
